﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Goldlight.Mvvm.Base;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.Windows.Interop;
using System.Collections.ObjectModel;
using System.Windows.Input;
using Goldlight.Mvvm.Base.Command;
using Goldlight.SampleApplication.LanguageResources;

namespace Goldlight.SampleApplication.ViewModels
{
    public enum HomePageMessages
    {
        ShowWorkspace,
        ShowSales,
        ShowMarketing,
        ShowService,
        ShowSettings,
        ShowResourceCentre
    }
    /// <summary>
    /// The homepage is the start page that controls what "mode" the user is in.
    /// </summary>
    public class HomePageViewModel : WorkspaceViewModelBase
    {
        #region Members
        private LanguageResources.Language _resources;
        private ObservableCollection<PageItem> _pages;
        #endregion

        /// <summary>
        /// Initialize a new instance of <see cref="HomePageViewModel"/>.
        /// </summary>
        public HomePageViewModel() : base()
        {
            _resources = new LanguageResources.Language();
            Name = LanguageResources.Language.StartPage;
        }

        protected override void OnInitialize()
        {
            base.OnInitialize();
            IsCloseable = false;
            _pages = new ObservableCollection<PageItem>();
            _pages.Add(new PageItem(Language.WorkplaceHeading, Language.WorkplaceText, @"..\Images\workspace.png", HomePageMessages.ShowWorkspace));
            _pages.Add(new PageItem(Language.SalesHeading, Language.SalesText, @"..\Images\chart.png", HomePageMessages.ShowSales));
            _pages.Add(new PageItem(Language.MarketingHeading, Language.MarketingText, @"..\Images\mail.png", HomePageMessages.ShowMarketing));
            _pages.Add(new PageItem(Language.ServiceHeading, Language.ServiceText, @"..\Images\users.png", HomePageMessages.ShowService));
            _pages.Add(new PageItem(Language.SettingsHeading, Language.SettingsText, @"..\Images\settings.png", HomePageMessages.ShowSettings));
            _pages.Add(new PageItem(Language.ResourceCentreHeading, Language.ResourceCentreText, @"..\Images\service.png", HomePageMessages.ShowResourceCentre));
        }
        /// <summary>
        /// Get the localized resources.
        /// </summary>
        public override object Resources
        {
            get
            {
                return _resources;
            }
        }

        /// <summary>
        /// Return the list of pages.
        /// </summary>
        public ObservableCollection<PageItem> Pages
        {
            get { return _pages; }
        }

        /// <summary>
        /// Encapsulation of a single "page" to be shown in the start screen.
        /// </summary>
        public class PageItem : ViewModelBase
        {
            private RelayCommand _pageCommand;
            private HomePageMessages _message;
            /// <summary>
            /// Initializes a new instance of <see cref="PagerItem"/>.
            /// </summary>
            /// <param name="title">The title to be displayed as the heading.</param>
            /// <param name="snippet">A brief description of the relevant area.</param>
            /// <param name="picture">The Uri of the image to be displayed against the item.</param>
            public PageItem(string title, string snippet, string picture, HomePageMessages message)
            {
                Title = title;
                Snippet = snippet;
                Picture = picture;
                _message = message;
            }

            /// <summary>
            /// Get the title.
            /// </summary>
            public string Title { get; private set; }
            /// <summary>
            /// Get the Uri of the image.
            /// </summary>
            public string Picture { get; private set; }
            /// <summary>
            /// Get the brief description.
            /// </summary>
            public string Snippet { get; private set; }
            /// <summary>
            /// Get the page command.
            /// </summary>
            public ICommand PageCommand
            {
                get
                {
                    if (_pageCommand == null)
                    {
                        _pageCommand = new RelayCommand(()=> Mediator.NotifyColleagues(_message, null));
                    }
                    return _pageCommand;
                }
            }
        }
    }
}
